<template>
  <div class="app-container">
    <el-dialog
      title="选择审核人"
      :visible.sync="saveOrEditTemplateDialog"
      :before-close="beforeClose"
      :close-on-click-modal="false"
    >
      <div class="checkerList">
        <el-form v-model="oaTemplate" :rules="rules" ref="form">
          <el-form-item label="模板名称" prop="tname">
            <el-input v-model.trim="oaTemplate.tname"></el-input>
          </el-form-item>
          <el-form-item label="模板类型" prop="ttype">
            <el-select v-model="oaTemplate.ttype">
              <el-option v-for="(item,index) in types" :value="item.id" :key="index" :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="添加用户" prop="usernames">
            <el-select v-model="oaTemplate.usernames" multiple >
              <el-option v-for="(item,index) in users" :value="item.userId" :key="index" :label="item.userName"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer">
        <el-button
          type="success"
          @click="submitForm"
          :loading="submitLoading">确 定</el-button>
        <el-button type="default" @click="closeDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import oaTemplateApi from '@/api/system/oaTemplate'
  export default {
    name: "OaTemplateSave",
    data() {
      return {
        saveOrEditTemplateDialog:false,
        submitLoading:false,
        oaTemplate:{
          sortIndex: 0,
          tid: "",
          tname: "",
          ttype: "",
          usernames: []
        },
        rules:{
          tname:[
            {required:true,message:'请输入模板名称',trigger:'blur'}
          ],
          ttype:[
            {required:true,message:'请选择模板类型',trigger:'change'}
          ],
          usernames:[
            {required:true,message:'请选择用户',trigger:'change'}
          ],
        }
      }
    },
    created() {

    },
    methods: {
      beforeClose(done){
        done(true)
      },
      submitForm(){
        this.$refs['form'].validate(valid=>{
          if(valid){
            this.saveOrUpdate()
          }
        })
      },
      saveOrUpdate(){
        this.submitLoading = true
        oaTemplateApi.save(this.oaTemplate).then(res=>{
          this.submitLoading = false
          if(res.success){
            this.$message.success('保存成功')
          }else{
            this.$message.warning('保存失败')
          }
        }).catch(err=>{
          console.log(err)
        })
      },
      closeDialog(){

      }
    }
  }
</script>

<style scoped lang="scss">

</style>
